package com.tianji.learning.config;

import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor;
import com.tianji.learning.utils.TableNameContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/7/7 18:46
 */

@Configuration
public class MybatisConfig {

    @Bean
    public DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor() {
        Map<String, TableNameHandler> tableNameHandlerMap = new HashMap<>(1);
        tableNameHandlerMap.put("points_board", (sql, tableName) -> TableNameContext.getTableName());
        return new DynamicTableNameInnerInterceptor(tableNameHandlerMap);
    }
}
